﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EasySite.Web.SessionCaches
{
    public abstract class SessionCacheBase<T> where T : class
    {
        protected abstract string Key { get; }

        protected abstract T Load();

        public T Value
        {
            get
            {
                if (HttpContext.Current.Session[Key] == null)
                {
                    HttpContext.Current.Session[Key] = Load();
                }
                return HttpContext.Current.Session[Key] as T;
            }
            set { HttpContext.Current.Session[Key] = value; }
        }
    }
}